package com.yujistu.fragment.mefragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.andexert.library.RippleView;
import com.bumptech.glide.Glide;
import com.yujistu.R;
import com.yujistu.activity.CollectionActivity;
import com.yujistu.activity.CouponsActivity;
import com.yujistu.activity.NotificationActivity;
import com.yujistu.activity.SettingsActivity;
import com.yujistu.activity.WalletActivity;
import com.yujistu.adapter.BaseListAdapter;
import com.yujistu.fragment.BaseFragment;
import com.yujistu.global.GlobalContext;

/**
 * Created by S3YOGA on 2015/11/4.
 */
public class MeFragment extends BaseFragment implements RippleView.OnRippleCompleteListener {

    RippleView  notify;
    RippleView  settings;


    RippleView  LayoutCollection, LayoutCouspor, LayoutWallet;

    TextView  nameTV;
    ImageView avaterIV;

    View  mContentView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

       mContentView = inflater.inflate(R.layout.fragment_me, null);

        if(GlobalContext.getInstance().isLoginResult()){
            if(!TextUtils.isEmpty(GlobalContext.getInstance().getLogin().getData().getUser().getFirstname())){
                nameTV.setText(GlobalContext.getInstance().getLogin().getData().getUser().getFirstname());
            }
            if(!TextUtils.isEmpty(GlobalContext.getInstance().getLogin().getData().getUser().getHeadimageurl())){
                Glide.with(mActivity.getApplicationContext()).load(GlobalContext.getInstance().getLogin().getData().getUser().getHeadimageurl()).crossFade().centerCrop().into(avaterIV);
            }
        }

        avaterIV = (ImageView)mContentView.findViewById(R.id.portraitCIV);
        nameTV = (TextView)mContentView.findViewById(R.id.account_name);

        initViews();
        return mContentView;
    }

    @Override
    public BaseListAdapter getListAdapter() {
        return null;
    }

    private void initViews() {
        notify = (RippleView)mContentView.findViewById(R.id.notify);
        notify.setOnRippleCompleteListener(this);
        settings = (RippleView)mContentView.findViewById(R.id.settings);
        settings.setOnRippleCompleteListener(this);


        LayoutCollection = (RippleView)mContentView.findViewById(R.id.my_collection);
        LayoutCollection.setOnRippleCompleteListener(this);
        LayoutCouspor = (RippleView)mContentView.findViewById(R.id.my_cour);
        LayoutCouspor.setOnRippleCompleteListener(this);
        LayoutWallet = (RippleView)mContentView.findViewById(R.id.my_wallet);
        LayoutWallet.setOnRippleCompleteListener(this);
    }


    @Override
    public void onComplete(RippleView rippleView) {
        switch (rippleView.getId()){
            case R.id.notify:
                startActivity(new Intent(getActivity(), NotificationActivity.class));
                break;
            case R.id.settings:
                startActivity(new Intent(getActivity(), SettingsActivity.class));
                break;
            case R.id.my_collection:
                startActivity(new Intent(getActivity(), CollectionActivity.class));
                break;
            case R.id.my_cour:
                startActivity(new Intent(getActivity(), CouponsActivity.class));
                break;
            case R.id.my_wallet:
                startActivity(new Intent(getActivity(), WalletActivity.class));
                break;
        }


    }
}
